﻿using PLCS.Application.Contracts.HisTaskApp.Dtos;

namespace PLCS.App.OrderTask.ViewModels.HisInstruction;

public class HisInstructionViewModel : NavigationPagedCurdViewModel<HisInstructionDto, HisInstructionDto, IHisInstructionService>
{
    private string _instructionNo;
    private string _startTime = string.Empty, _endTime = string.Empty;

    public string InstructionNo
    {
        get { return _instructionNo; }
        set { SetProperty(ref _instructionNo, value); }
    }

    public string StartTime
    {
        get { return _startTime; }
        set { _startTime = value; RaisePropertyChanged(); }
    }

    public string EndTime
    {
        get { return _endTime; }
        set { _endTime = value; RaisePropertyChanged(); }
    }

    /// <summary>
    /// 获取数据
    /// </summary>
    /// <param name="pageIndex"></param>
    public override async Task GetPageData(int pageIndex)
    {
        try
        {
            UpdateLoading(true);
            var res = await _service.GetListBySearchAsync((pageIndex - 1) * PageSize, PageSize, InstructionNo, StartTime, EndTime);
            TotalCount = (int)res.TotalCount;
            SetPageCount();
            DataGridList = res.Items.ToObservable();
        }
        finally
        {
            UpdateLoading(false);
        }
    }

    public HisInstructionViewModel(IHisInstructionService service) : base(service)
    {
    }
}